import function as func


class chat(object):
    def __init__(self):
        pass

    @staticmethod
    def start():
        choose = str(input('\n 1.ESPtools \n2.serial tools \nexit\n'))
        return choose

    @staticmethod
    def esptool():
        choose = int(
            input('1.Cleaning a ESP_chips \n2.Writing on a ESP_chip \n3.Reading the MAC of the ESP_chip \n '))
        return choose

    @staticmethod
    def serials():
        choose = int(input('1.Finding the COM channel \n2.Preparing for the serial \n3.The DOS system of serial \n '))
        return choose

    @staticmethod
    def esptool1():
        ESP_chips = str(input('Input ESP_chips type (caps):'))
        channel = int(input('Input the channel of the ESP_chip:COM'))
        try:
            func.clean_flash(ESP_chips, channel)
        except Exception:
            pass

    @staticmethod
    def esptool2():
        ESP_chips = str(input('Input ESP_chips type (caps):'))
        channel = str(input('Input the channel of the ESP_chip:COM'))
        Write_baud = str(input('Input the baud of writing on ESP_chips:'))
        place = str('0x'+input('Input the place of ESP_chips:(16)0x'))
        filename = str(input('Input the filename of write:'))
        try:
            func.write_flash(ESP_chips, channel, Write_baud, place, filename)
        except Exception:
            pass

    @staticmethod
    def esptool3():
        channel = str(input('Input ESP_chips type (caps):'))
        try:
            func.read_mac(channel)
        except Exception:
            pass

    @staticmethod
    def serial1():
        func.find_serial()

    @staticmethod
    def serial2():
        channel = str(input('Input the channel of the ESP_chip:COM'))
        baud = str(input('Input the baud of chat with chips:'))
        timeout = float(input('Input the second of serial timeout:'))
        device = func.serial_ready(channel, baud, timeout=timeout)
        return device

    @staticmethod
    def serial3(device):
        print('-*-*-*-*- serial DOS -*-*-*-*-')
        while True:
            text = str(input())
            if text == 'exit':
                exit()
            else:
                func.write_serial(device, text)
            func.read_serial(device)
